package Servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

/**
 * Created by liushiyin on 2017/11/15.
 */
public class RedirectIndex extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");

        Vector<String> list1=new Vector<>();
        Vector<String> list2=new Vector<>();
        BufferedReader in=new BufferedReader(new FileReader("/home/liushiyin/outres.txt"));
        String link;
        String title;
        int count=0;
        do {
            link=in.readLine();
            title=in.readLine();
            list1.add(link);
            list2.add(title);
            ++count;
            if(count>=17){
                break;
            }
        }while (link!=null&&title!=null);
        request.setAttribute("list1",list1);
        request.setAttribute("list2",list2);
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
}
